@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>

    @endsection

    @section('html-body')
            <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.answerList')}}?id={{$id}}">选项管理</a>
            <em>></em>
            <a href="#">设置选项</a>
        </div>
        <!-- cur-position end -->

        <div class="gg-step">
            <form  id="advform">
                <input type="hidden" name="id" id="id" value="@if($sysAnswer){{$sysAnswer->id}} @endif"/>
                <input type="hidden" name="id" id="taId" value="{{$id}}"/>


                <div class="fill-list">
                    <span class="fill-tit">选项编号：</span>
                    <select id="select_num">
                        <option value="A" @if($sysAnswer && $sysAnswer->answer_num == 'A') selected @endif>A</option>
                        <option value="B" @if($sysAnswer && $sysAnswer->answer_num == 'B') selected @endif>B</option>
                        <option value="C" @if($sysAnswer && $sysAnswer->answer_num == 'C') selected @endif>C</option>
                        <option value="D" @if($sysAnswer && $sysAnswer->answer_num == 'D') selected @endif>D</option>
                        <option value="E" @if($sysAnswer && $sysAnswer->answer_num == 'E') selected @endif>E</option>
                        <option value="F" @if($sysAnswer && $sysAnswer->answer_num == 'F') selected @endif>F</option>
                        <option value="G" @if($sysAnswer && $sysAnswer->answer_num == 'G') selected @endif>G</option>
                    </select>
                </div>

                <div class="fill-list">
                    <span class="fill-tit">选项内容：</span>
                    <input class="fill-ipt" type="text" name="answer" id="answer" value="@if($sysAnswer) {{$sysAnswer->answer}} @endif">
                </div>

                <div class="fill-list">
                    <span class="fill-tit">是否答案：</span>
                    <input type="radio" name="select_answer" id="is_right" value="1" @if($sysAnswer && $sysAnswer->select_answer == 1) checked @endif>是
                    <input type="radio" name="select_answer" id="no_right" value="0" @if($sysAnswer && $sysAnswer->select_answer == 0) checked @endif>否
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn_send">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>
        $(function() {

            $('#btn_send').click(function () {
                var answer          = $('#answer').val();
                var answer_num      = $('#select_num option:selected').val();
                var select_answer   = $("input[name='select_answer']:checked").val();
                var taId            = $('#taId').val();
                var id              = $('#id').val();

                $.ajax({
                    url: '{{route("Api.Admin.sys.setAnswer")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        answer:answer,
                        answer_num:answer_num,
                        select_answer:select_answer,
                        ta_id:taId,
                        id:id
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.href="{{route('Admin.Home.answerList')}}?id="+taId;
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
        });
        });

    </script>
@endsection